First I need to explain something.
flamingo.py is a text project that I made for a library called Tkinter.
It's called flamingo.py because it has a image of a flamingo in it.
I made it to learn how to use Tkinter so it's just a simple project.
Probably you think right now something like this:
How to install tkinter?
As it states on tkinter documentation:
The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit.
Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems.
In other words you should have it installed with python.
After getting that out of the way let's just get straight to the code.
from tkinter import *
You need to import the library first.
a = Tk()
a.geometry("400x400")
a.geometry("400x400") is for the window size.
If you want you can change a = Tk() to something else
For example: i = Tk()
a.resizable(width= False, height=False)
a.configure(bg="pink", cursor "heart")
a.resizable(width=False, height=False) is for disabling an option for user to risize the window
a.configure(bg="pink", cursor="heart") changes background to pink (bg="pink",) and changes how the cursor looks
img = PhotoImage(file="flamingo.png")
Here you need an image file named "flamingo.png".
You can find it here.
canvas = Canvas(a, width = 400, height = 400,
bg = "pink",bd=0, highlightthickness=0)
The Canvas is a rectangular area intended for drawing pictures or other complex layouts. You can place graphics, text, widgets or frames on a Canvas.
width = 400 changes the width of the image.
height = 400 changes height of the image.
bg = "pink" makes the background pink.
bd = 0 changes the border size.
canvas.pack()
Create the canvas.
canvas.create_image(20,20,anchor=NW, image=img)
Changes the place where the canvas is created.
a.title("flamingo")
Changes the window title.
a.iconphoto(False, img)
Change the icon (img is a variable from earlier(img = PhotoImage(file="flamingo.png")))
a.mainloop()
You need this to keep the window running.
Here is the full code:
from tkinter import *
a = Tk()
a.geometry("400x400")
a.resizable(width=False, height=False)
a.configure(bg="pink", cursor="heart")
img = PhotoImage(file="flamingo.png")
canvas = Canvas(a, width = 400, height = 400,
bg = "pink",bd=0, highlightthickness=0)
canvas.pack()
canvas.create_image(20,20,anchor=NW, image=img)
a.title("flamingo")
a.iconphoto(False, img)
a.mainloop()
Also you can find it here.
That's it! Good job.Now you can leave!
Press here!
ok you asked for it
ok you can now leave